home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / tcclib.exe / WINLIST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-07  |  4.7 KB  |  174 lines

  1. #include "tcclib.h"
  2. #include <conio.h>
  3. #include <dos.h>
  4.  
  5. int WindowLister( int x,
  6.                   int y,
  7.                   int xx,
  8.                   int yy,
  9.                   int CharToExitOn,
  10.                   int *NumItems,
  11.                   int NumToStartWith,
  12.                   int (*CharHandler)(int ch, int Index),
  13.                   void (*ScreenClearer)( void ),
  14.                   void (*DisplayLineFunction)(int Index) )
  15. {
  16.     register int i;
  17.     register int CurrLine = 0;
  18.     int PrevLine;
  19.     int NumLines = yy - y;
  20.     int Top = NumToStartWith;
  21.     int OldTop;
  22.     int RefreshScreen = 1;
  23.     int ch;
  24.     union REGS regs, regs2;
  25.     int Index;
  26.  
  27.     regs.x.cx = ( (y-1) << 8 ) + x-1;
  28.     regs.x.dx = ( (yy-1) << 8 ) + xx-1;
  29.     regs.x.ax = 0;
  30.     regs.h.bh = A_NORMAL;
  31.     regs.h.ah = 0x06;
  32.     regs.x.ax = 1;
  33.  
  34.     for (;;) {
  35.  
  36.         if ( RefreshScreen ) {
  37.             ScreenClearer();
  38.             ChangeBlock( x, y, xx, yy, A_NORMAL );
  39.             RefreshScreen = 0;
  40.             PrevLine = 500;
  41.             OldTop = -500;
  42.             for (i=0; i<=NumLines; ++i) {
  43.                 gotoxy( x, i+y );
  44.                 if ( i+Top <= *NumItems )
  45.                     DisplayLineFunction( i+Top );
  46.             }
  47.         }
  48.  
  49.         Index = CurrLine + Top;
  50.  
  51.         if ( PrevLine != CurrLine || OldTop != Top ) {
  52.             SetAttrib( A_REVERSE );
  53.             gotoxy( x, y + CurrLine );
  54.             DisplayLineFunction( Index );
  55.             SetAttrib( A_NORMAL );
  56.         }
  57.         HideCursor();
  58.  
  59.         PrevLine = CurrLine;
  60.         OldTop = Top;
  61.  
  62.         ch = GComm();
  63.         if ( ch == CharToExitOn ) return( Index );
  64.  
  65.         switch( ch ) {
  66.  
  67.             case ESC:
  68.                 return( -1 );
  69.  
  70.             case DOWN:
  71.                 CurrLine++;
  72.                 if (CurrLine > NumLines) {
  73.                     CurrLine = NumLines;
  74.                     if ( Top < *NumItems - NumLines ) {
  75.                         Top++;
  76.                            ChangeBlock( x, y, xx, yy, A_NORMAL );
  77.                         regs.h.ah = 0x06;
  78.                         int86( 0x10, ®s, ®s2 );
  79.                         gotoxy( x, yy );
  80.                     }
  81.                 }
  82.                 break;
  83.  
  84.             case UP:
  85.                 CurrLine--;
  86.                 if (CurrLine < 0) {
  87.                     CurrLine=0;
  88.                     if ( Top > 0 ) {
  89.                         Top--;
  90.                            ChangeBlock( x, yy, xx, yy, A_NORMAL );
  91.                         regs.h.ah = 7;
  92.                         int86( 0x10, ®s, ®s2 );
  93.                         gotoxy( x, y );
  94.                     }
  95.                 }
  96.                 break;
  97.  
  98.             case END:
  99.                 Top = *NumItems - NumLines;
  100.                 if ( Top < 0 ) {
  101.                     Top = 0;
  102.                 }
  103.                 CurrLine = NumLines;
  104.                 if ( CurrLine > *NumItems ) {
  105.                     CurrLine = *NumItems;
  106.                 }
  107.                 RefreshScreen++;
  108.                 break;
  109.  
  110.             case PGDN:
  111.                 Top += NumLines;
  112.                 if (Top > *NumItems - NumLines) {
  113.                     Top = *NumItems - NumLines;
  114.                     if ( Top < 0 )
  115.                         Top = 0;
  116.                     CurrLine = NumLines;
  117.                     if ( CurrLine > *NumItems ) {
  118.                         CurrLine = *NumItems;
  119.                     }
  120.                 }
  121.                 RefreshScreen++;
  122.                 break;
  123.  
  124.             case PGUP:
  125.                 Top -= NumLines;
  126.                 if (Top < 0) {
  127.                     Top = 0;
  128.                     CurrLine = 0;
  129.                 }
  130.                 RefreshScreen++;
  131.                 break;
  132.  
  133.             case HOME:
  134.                 Top = CurrLine = 0;
  135.                 RefreshScreen++;
  136.                 break;
  137.  
  138.             default:
  139.                 gotoxy( x, CurrLine + y );
  140.                 ReverseText();
  141.                 DisplayLineFunction( Index );
  142.                 NormalText();
  143.                 /*HideCursor();*/
  144.                 RefreshScreen++;
  145.                 CurrLine = CharHandler( ch, Index );
  146.                 RefreshScreen = 1;
  147.                 if ( CurrLine - Top <= NumLines && CurrLine - Top >= 0 )
  148.                     CurrLine -= Top;
  149.                 else {
  150.                     Top = CurrLine - 1;
  151.                     CurrLine = 1;
  152.                     if ( Top < 0 ) {
  153.                         Top = CurrLine = 0;
  154.                     }
  155.                 }
  156.                 break;
  157.  
  158.         }
  159.         if ( Top < 0 ) {
  160.             Top = 0;
  161.             CurrLine = 0;
  162.         }
  163.         if ( Top + CurrLine > *NumItems ) {
  164.             CurrLine = *NumItems - Top;
  165.         }
  166.         if ( PrevLine != CurrLine || Top != OldTop ) {
  167.             ChangeBlock( x, y, xx, yy, A_NORMAL );
  168.         }
  169.         if ( RefreshScreen > 1 ) {
  170.             Top = CurrLine = 0;
  171.         }
  172.     }
  173. }
  174.